<?php
require_once 'BaseMySQLDAO.php';

class ChatOnlineDAO extends BaseMySQLDAO {

    public function __construct($context) {
        parent::__construct($context, 'device');
    }
    
 	public function getChatOnline($start, $limit) {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction();
            
            $inSQL = "SELECT * FROM chat_online";
            
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL, $param);
            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function insertChatOnline($param) {
        $result = null;
        try {
            $inSQL = "INSERT INTO
                        chat_online(id, name, text, upb, upi, upu, upcolor, upfont, ip)
                        VALUES (
                            :id, :name, :text, :upb, :upi, :upu, :upcolor, :upfont, :ip
                        )";
            $queryParam = array(
                                ':id' => NULL,
                                ':name' => $param['name'],
            					':text' => $param['text'],
            					':upb' => $param['upb'],
            					':upi' => $param['upi'],
            					':upu' => $param['upu'],
            					':upcolor' => $param['upcolor'],
            					':upfont' => $param['upfont'],
            					':ip' => $param['ip']
                            );
            $this -> getContext() -> getTransaction() -> startTransaction('thanhphogame');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();       

        } catch (Exception $exception) {
            print_r($exception);
            exit;
        }
        return $result;
    }
    
	
	public function deleteDevice($id) {
        try {

            $inSQL = "   DELETE FROM device WHERE id = :id ";
            $queryParam = array(':id' => $id);

            $this -> getContext() -> getTransaction() -> startTransaction('thanhphogame');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();
            
            $this -> getContext() -> getTransaction() -> startTransaction('mobile');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();

            $this -> getContext() -> getTransaction() -> startTransaction('choigamemobi');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();

            $this -> getContext() -> getTransaction() -> startTransaction('mymobigame');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();
            
            $this -> getContext() -> getTransaction() -> startTransaction('ngoisaogamethu');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
            return false;
        }
        return true;
    }
}
?>